<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">
    <ui:define name="head-title">
        <title>Add New Customer | Merlion's ERP System</title>
    </ui:define>
    
    
    <ui:define name="content">
        
        <p:panel id="panel" header="Add New Customer"> 
            <p:ajaxStatus style="width:16px;height:16px;">   
                <f:facet name="start">   
                    <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" /> 
                </f:facet> 

                <f:facet name="complete">   
                    <h:outputText value="" />   
                </f:facet>   
            </p:ajaxStatus> 

            <p:messages /> 

            <h:form prependId="false">
                <p:commandButton id="btn" value="Save New Customer" update="panel" actionListener="#{addCustomerManagerBean.saveNewCustomer(event)}">
                </p:commandButton>
                <h:panelGrid columns="3" cellpadding="10"> 
                    
                    <h:outputLabel for="customerName" style="font-weight: bold" value="Company Name: " /> 
                    <p:inputText value="#{addCustomerManagerBean.customerName}" required="true" label="Company Name" requiredMessage="Customer Name is required." id="customerName"> 
                    </p:inputText> 
                    <p:message for="customerName" /> 
                    
                    <h:outputLabel for="registrationNumber" style="font-weight: bold" value="Registration Number: " /> 
                    <p:inputText id="registrationNumber" value="#{addCustomerManagerBean.registrationNumber}" required="true" label="registrationNumber" requiredMessage="Registration Number is required." validator="#{saleLeadManagerBean.validateRegNum}"> 
                    </p:inputText> 
                    <p:message for="registrationNumber" /> 
 
                    <h:outputLabel for="address" style="font-weight: bold" value="Address: " /> 
                    <p:inputText id="address" value="#{addCustomerManagerBean.address}" required="true" label="address" requiredMessage="Address is required.">                         
                    </p:inputText> 
                    <p:message for="address" /> 
                    
                    <h:outputLabel for="customerType" style="font-weight: bold" value="Customer Type: " /> 
                    <h:selectOneMenu id ="customerType" value="#{addCustomerManagerBean.customerType}">
                        <f:selectItem itemValue="WholeSale" itemLabel="Whole Sale" id="wholeSale" />
                        <f:selectItem itemValue="DirectSale" itemLabel="Direct Sale" id="directSale" />
                    </h:selectOneMenu>
                    
                    <p:message for="customerType" />
                    
                </h:panelGrid>
                
                <p:dataTable value="#{addCustomerManagerBean.reps}" var="rep" id="repTable">
                    <p:column sortBy="#{rep.name}" style="width: 30%"> 
                        <f:facet name="header"> 
                            <h:outputText value="Representative Name" /> 
                        </f:facet> 
                        <h:outputText value="#{rep.name}" /> 
                    </p:column>

                    <p:column sortBy="#{rep.email}" style="width: 40%"> 
                        <f:facet name="header"> 
                            <h:outputText value="Email" /> 
                        </f:facet> 
                        <h:outputText value="#{rep.email}" /> 
                    </p:column>

                    <p:column sortBy="#{rep.contactNumber}" style="width: 30%"> 
                        <f:facet name="header"> 
                            <h:outputText value="Contact Number" /> 
                        </f:facet> 
                        <h:outputText value="#{rep.contactNumber}" /> 
                    </p:column>
                </p:dataTable>
                <br />
                
        </h:form>
            <h:form id="form1" prependId="false">
                <p:commandButton id="btn1" value="Add new Representative" actionListener="#{addCustomerManagerBean.add(event)}" update="form1 abc" ajax="true"/>                
            </h:form>
            
            
        </p:panel>
        
        <h:form prependId="false">
            <p:outputPanel id="abc">
            <p:panel id="panel1" rendered="#{addCustomerManagerBean.display}">
                <h:panelGrid id="display3" columns="3" >
                    <h:outputText value="Representative Name:"/>
                    <p:inputText id="name" value="#{addCustomerManagerBean.newRep.name}" required="true" requiredMessage="Name is required"/>
                    <p:message for="name"/>
                    <h:outputText value="Representative Email:"/>
                    <p:inputText id="email" value="#{addCustomerManagerBean.newRep.email}" required="true" requiredMessage="Email is required"  validator="#{saleLeadManagerBean.validateEmail}"/>
                    <p:message for="email"/>
                    <h:outputText value="Representative Contact Number: "/>
                    <p:inputText id="contact" value="#{addCustomerManagerBean.newRep.contactNumber}" required="true" requiredMessage="Contact Number is required" validator="#{saleLeadManagerBean.validateContactNumber}"/>
                    <p:message for="contact"/>
                    <p:commandButton value="Add" actionListener="#{addCustomerManagerBean.addRep(event)}" update="panel2 repTable display3"/>  
                </h:panelGrid>
            </p:panel> 
            </p:outputPanel>
        </h:form>

    </ui:define>

</ui:composition>
